package com.qf.agro.controller;

import com.qf.agro.common.ResultInfo;
import com.qf.agro.pojo.SmartDeviceDataLogs;
import com.qf.agro.service.DeviceDataLogsService;
import com.qf.agro.util.EasyExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 10202
 * @version V1.0
 * @Project smart-agriculture-parent
 * @Package com.qf.agro.controller
 * @Date 2023/7/4 14:56
 */
@RestController
@RequestMapping("device/dataLogs")
public class DeviceDataLogsController {

    @Autowired
    private DeviceDataLogsService deviceDataLogsService;


    @GetMapping("page")
    public ResultInfo getpage(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "5")Integer pageSize,Long facilitiesId,Long deviceId
    ,Integer day,Integer resultCode)
    {

        return deviceDataLogsService.getPage(pageNum,pageSize,facilitiesId,deviceId,day,resultCode);

    }

    @GetMapping("export")
    public void export(Long facilitiesId, Long deviceId, Integer day, Integer resultCode, HttpServletResponse response){
        //1.调用业务层查询
        List<SmartDeviceDataLogs> smartDeviceDataLogs = deviceDataLogsService.findList(facilitiesId,deviceId,day,resultCode);
        //2.使用工具类把集合导出到excel中
        EasyExcelUtils.exportExcel(smartDeviceDataLogs,SmartDeviceDataLogs.class,"智能设备日志记录","智能设备日志记录",response);


    }
}
